function readtiled() {
    let canvas = document.getElementById("_canvas3");
    canvas.style.display = 'block';
    let ctx = canvas.getContext("2d");
    let engine = new Engine(ctx);
    let layer = new Layer(ctx);
    engine.addLayer(layer);

    //读取块大小
    //读取块高数量
    //读取块宽数量
    //过滤得到需要绘制的块，及其坐标
    //循环绘制块

    //完全超出当前画布的块不绘制
    //加入块的偏移地址
    //加入移动功能（动态偏移）

    let map;
    layer.preload = function () {
        map = TiledUtil.loadMap(TileMaps.tank);
    }

    layer.create = function () {
        let tilemap = new TileMapObject(map);
        layer.addObject(tilemap);

        let player = new ArcObject(10);
        player.x = canvas.width / 2;
        player.y = canvas.height / 2;
        player.realX = player.x;
        player.realX = player.y;
        player.follower = tilemap;
        player.update = function (delta) {
            let speed = 10;
            let xmove = 0;
            let ymove = 0;
            if (Input.keybord_down_check('A')) {
                xmove -= speed * delta
            }
            if (Input.keybord_down_check('D')) {
                xmove += speed * delta
            }
            if (Input.keybord_down_check('W')) {
                ymove -= speed * delta
            }
            if (Input.keybord_down_check('S')) {
                ymove += speed * delta
            }
            if (xmove === 0 && ymove === 0) {
                return;
            }

            if (player.follower) {
                player.follower.follow(this, xmove, ymove);
            } else {
                player.x += xmove;
                player.y += ymove;
            }
        }

        layer.addObject(player);
    }
    engine.run();

    function TileMapObject(map) {
        this.init();
        this.tiledata = map.tiledata;

        let viewport = {
            x: 0,
            y: 0,
            xmove: 0,
            ymove: 0
        };

        this.ready = function () {
            let canvas = this.ctx.canvas;
            viewport.width = canvas.width;
            viewport.height = canvas.height;

            this.x = map.baseX;
            this.y = map.baseY;
            this.width = map.mapWidth * map.tilewidth;
            this.height = map.mapHeight * map.tileheight;

            viewport.xrange = [canvas.width - (this.x + this.width), 0 - this.x];
            viewport.yrange = [canvas.height - (this.y + this.height), 0 - this.y];
        };

        let isOutCanvas = dot => (dot.x < 0 || dot.x > canvas.width) && (dot.y < 0 || dot.y > canvas.height);

        this.update = function () {
            for (const d of this.tiledata) {
                //计算坐标和图片slice参数
                d.dx = d._dx + viewport.xmove;
                d.dy = d._dy + viewport.ymove;

                let dot1 = { x: d.dy, y: d.dy };
                let dot2 = { x: d.dy + d.dWidth, y: d.dy };
                let dot3 = { x: d.dy + d.dWidth, y: d.dy + d.dHeight };
                let dot4 = { x: d.dy, y: d.dy + d.dHeight };
                d.hidden = isOutCanvas(dot1) && isOutCanvas(dot2) && isOutCanvas(dot3) && isOutCanvas(dot4);
            }
        }
        this.draw = function () {
            let hideCount = 0;
            for (const d of this.tiledata) {
                if (d.hidden) {
                    hideCount++;
                    continue;
                }
                this.ctx.drawImage(d.image, d.sx, d.sy, d.sWidth, d.sHeight, d.dx, d.dy, d.dWidth, d.dHeight);
            }
            if (hideCount > 0) {
                // console.log('隐藏图块数量:', hideCount);
            }
        }
        this.follow = function (player, xmove, ymove) {
            if (xmove === 0 && ymove === 0) {
                return;
            }
            let distanceToEdge = 100;
            let movePlayer = xmove < 0 && player.x > distanceToEdge - xmove
                || xmove > 0 && player.x < canvas.width - distanceToEdge - xmove
                || ymove < 0 && player.y > distanceToEdge - ymove
                || ymove > 0 && player.y < canvas.height - distanceToEdge - ymove;

            if (movePlayer) {
                player.x += xmove;
                player.y += ymove;
            } else {
                //地图的运动方向和玩家相反
                viewport.xmove = MathUtil.limitValue(viewport.xmove - xmove, viewport.xrange);
                if (MathUtil.anyEqual(viewport.xmove, viewport.xrange)) {
                    player.x += xmove;
                }
                viewport.ymove = MathUtil.limitValue(viewport.ymove - ymove, viewport.yrange);
                if (MathUtil.anyEqual(viewport.ymove, viewport.yrange)) {
                    player.y += ymove;
                }
            }
        }
    }
    TileMapObject.prototype = new GameObject();
    return engine;
}